package com.example.sens.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.example.sens.entity.Conclusion;
import com.example.sens.entity.Performance;
import com.example.sens.entity.Quiz;
import com.example.sens.service.ConclusionService;
import com.example.sens.utils.Response;
import com.example.sens.vo.ConclusionVo;
import com.example.sens.vo.QuizVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/conclusion")
public class ConclusionController {

    @Autowired
    private ConclusionService conclusionService;

    /**
     * 获取分页数据
     * @param conclusionVo
     * @return
     */
    @PostMapping("/getByPage")
    public Response<Page<Conclusion>> getByPage(@RequestBody ConclusionVo conclusionVo) {
        Page<Conclusion> quizPage = null;
        try {
            quizPage = conclusionService.findAll(new Page(conclusionVo.getPageNo(), conclusionVo.getPageSize()));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.no();
        }
        return Response.yes(quizPage);
    }

    @PostMapping("/updateScore")
    public Response updateScore(@RequestParam("id") Long id,
                                @RequestParam("score") Integer score,
                                @RequestBody Performance performance) {
        Conclusion conclusion = new Conclusion();
        conclusion.setId(id);
        conclusion.setScore(score);
        return conclusionService.updateScore(conclusion,performance);
    }

}
